
uniform sampler2D textureMap;

uniform vec2 offset[9];
uniform int kernel[9];

varying vec2 texcoord; // not currently in use

void main() {

        //vec4 sum = vec4(0.0);
        float gmax = 0.0;
	float gmin =1.0;
             
        int i;
        float g;
        for (i=0 ; i<9; i++){
            vec4 color = texture2D(textureMap, gl_TexCoord[0].st + offset[i]);
            g = color.r;
            if (g > gmax) gmax = g;
            if (g < gmin) gmin = g; 
        } 

        float kp = 0.18;// up for tuning
        float value = ((gmax - gmin)/kp);
        value = value*value; // square it
        float color = min(value, 1.0);

	gl_FragColor = vec4(color, color, color, 1);
}
